function sendRequest() {
  const xhr = new XMLHttpRequest()

  // 请求超时时间，单位 ms
  xhr.timeout = 1000

  // 请求超时事件监听
  xhr.ontimeout = event => {
    console.log('ontimeout', event)
  }

  xhr.open('GET', 'http://127.0.0.1/api/get')
  xhr.onreadystatechange = () => {
    if (xhr.readyState === XMLHttpRequest.DONE) {
      if (xhr.status === 200) {
        const res = xhr.response
        console.log(res)
      }
    }
  }
  xhr.send()
}
